#include "function.h"
#include "parameterlist.h"
#include "parameter.h"
#include "component.h"
#include "errorlog.h"

Function::Function(const QString& name, ParameterList* params, const Type& type, const YYLTYPE& loc)
    : Namespace( loc ), m_name(name), m_params( params ), m_type(type)
{
    appendChild( params );
}

Node* Function::getEntry( const QString& name )
{
    return m_params->parameter(name);
}

QString Function::jsName() const
{
    if ( m_name[0] == '$' || m_name[0] == '#' )
        return m_name.mid(1);
    return m_name;
}

UserFunction::UserFunction(const QString& name, ParameterList* params, const QString& body, const Type& type, const YYLTYPE& loc)
    : Function(name, params, type, loc), m_body(body)
{
}

MemberFunction::MemberFunction(const QString& name, ParameterList* params, const QString& body, const Type& type, const YYLTYPE& loc)
    : UserFunction( name, params, body, type, loc )
{
}

Component* MemberFunction::component() const
{
    return dynamic_cast<Component*>(parentNode()->parentNode());
}
